﻿using System.Collections.Generic;

namespace Sustainalytics.Caching
{
    /// <summary>
    /// Cache item.
    /// </summary>
    public class AppCacheItem
    {
        /// <summary>
        /// Cache item key.
        /// </summary>
        public string Key { get; private set; }

        /// <summary>
        /// Cache item value.
        /// </summary>
        public object Value { get; private set; }


        /// <summary>
        /// Ctor.
        /// </summary>
        /// <param name="key"> Cache item key. </param>
        /// <param name="value"> Cache item value. </param>
        public AppCacheItem(string key, object value)
        {
            if (string.IsNullOrEmpty(key))
            {
                throw new CacheItemKeyNullOrEmptyException();
            }

            this.Key = key;
            this.Value = value;
        }

        /// <summary>
        /// Get value as bytes array.
        /// </summary>
        /// <returns> Value as bytes array. </returns>
        public byte[] ValueAsBytes()
        {
            return (byte[])this.Value;
        }

        /// <summary>
        /// Get value as string.
        /// </summary>
        /// <returns> Value as string. </returns>
        public string ValueAsString()
        {
            return (string)this.Value;
        }

        /// <summary>
        /// Get value as a an enumerable.
        /// </summary>
        /// <returns> Enumerable of strings. </returns>
        public IEnumerable<string> ValueAsEnumerable()
        {
            return (IEnumerable<string>)this.Value;
        }
    }
}
